package com.poi.controller;

import com.poi.domain.User;
import com.poi.utils.ExcelExportUtil;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.util.ArrayList;

/**
 * Created by fangjicai on 2020/6/5.
 */
@RestController
public class TestController {
    @RequestMapping(value = "/export", method = RequestMethod.GET)
    public void export(HttpServletResponse response) throws Exception {
        //1.模拟数据
        ArrayList<User> list = new ArrayList<User>();
        for(int i=0;i<10;i++){
            list.add(new User(i,i+"test",10+i));
        }
        //2.加载模板流数据
        Resource resource = new ClassPathResource("user.xlsx");
        FileInputStream fis = new FileInputStream(resource.getFile());
        //以模板表第二行中cell样式
        new ExcelExportUtil(User.class,1,1).
                export(response,fis,list,"test.xlsx");
    }

}
